package spring.factory;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.config.SingletonBeanRegistry;

public class SingletonBeanRegister implements SingletonBeanRegistry {


    private final Map<String, Object> BEANS = new HashMap<>();

    @Override
    public boolean containsSingleton(String beanName) {
        return BEANS.containsKey(beanName);
    }

    @Override
    public Object getSingleton(String beanName) {
        return BEANS.get(beanName);
    }

    @Override
    public int getSingletonCount() {
        return BEANS.size();
    }

    @Override
    public String[] getSingletonNames() {
        return BEANS.keySet().toArray(new String[0]);
    }

    @Override
    public void registerSingleton(String beanName, Object bean) {
        if (BEANS.containsKey(beanName)) {
            return;
        }
        BEANS.put(beanName, bean);

    }

}
